import java.util.List;

public class NC78 {
    public ListNode ReverseList(ListNode head) {
        if (head==null){
            return null;
        }
        ListNode pre = null;
        ListNode next = null;

        while (head!=null){
            next = head.next;
            // next.next = head;  死循环
            head.next = pre;
            pre = head;
            head = next;
        }
        return pre;
    }

    public static void main(String[] args) {
        ListNode listNode1 = new ListNode(1);
        ListNode listNode2 = new ListNode(2);
        ListNode listNode3 = new ListNode(3);
        ListNode listNode4 = new ListNode(4);

        listNode1.next=listNode2;
        listNode2.next=listNode3;
        listNode3.next=listNode4;
        NC78 nc78 = new NC78();
        nc78.ReverseList(listNode1);
    }
}
